document.addEventListener('DOMContentLoaded', () => {
    // Video background handling
    const video = document.getElementById('bgVideo');
    if (video) {
        // Ensure video plays on mobile devices
        video.play().catch(function(error) {
            console.log("Video autoplay failed:", error);
        });

        // Handle video loading
        video.addEventListener('loadeddata', () => {
            video.style.opacity = '1';
        });
    }

    // Smooth scroll for CTA button
    const ctaButton = document.querySelector('.cta-button');
    if (ctaButton) {
        ctaButton.addEventListener('click', (e) => {
            e.preventDefault();
            const targetSection = document.querySelector(ctaButton.getAttribute('href'));
            if (targetSection) {
                targetSection.scrollIntoView({
                    behavior: 'smooth'
                });
            }
        });
    }

    // Add parallax effect to header content
    const headerContent = document.querySelector('.header-content');
    if (headerContent) {
        window.addEventListener('scroll', () => {
            const scrolled = window.pageYOffset;
            headerContent.style.transform = `translateY(${scrolled * 0.5}px)`;
            headerContent.style.opacity = 1 - (scrolled / 500);
        });
    }

    // Add intersection observer for fade-in animations
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('visible');
            }
        });
    }, {
        threshold: 0.1
    });

    // Observe elements with fade-in class
    document.querySelectorAll('.fade-in').forEach((element) => {
        observer.observe(element);
    });

    // Handle video fallback
    const checkVideoSupport = () => {
        const video = document.getElementById('bgVideo');
        if (video) {
            if (video.canPlayType) {
                const videoOverlay = document.querySelector('.video-overlay');
                if (!video.canPlayType('video/mp4').length) {
                    video.style.display = 'none';
                    if (videoOverlay) {
                        videoOverlay.style.background = 'linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7))';
                    }
                }
            }
        }
    };

    checkVideoSupport();
}); 